<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>银行业务管理系统 - 交易管理</title>
    <!-- 引入Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- 配置Tailwind -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#1890ff',
                        secondary: '#40a9ff',
                        success: '#52c41a',
                        warning: '#faad14',
                        danger: '#ff4d4f',
                        info: '#8c8c8c',
                        light: '#fafafa',
                        dark: '#1f2937'
                    },
                    fontFamily: {
                        sans: ['Microsoft YaHei', 'Inter', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .card-shadow {
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
            }
            .card-hover {
                transition: all 0.3s ease;
            }
            .card-hover:hover {
                transform: translateY(-2px);
                box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
            }
            .btn-primary {
                @apply bg-primary text-white px-4 py-2 rounded-md hover:bg-secondary transition-colors duration-200;
            }
            .btn-secondary {
                @apply bg-white text-primary border border-primary px-4 py-2 rounded-md hover:bg-primary/5 transition-colors duration-200;
            }
            .btn-danger {
                @apply bg-danger text-white px-4 py-2 rounded-md hover:bg-danger/90 transition-colors duration-200;
            }
            .btn-warning {
                @apply bg-warning text-white px-4 py-2 rounded-md hover:bg-warning/90 transition-colors duration-200;
            }
            .input-control {
                @apply border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all duration-200;
            }
            .table-row-hover {
                @apply hover:bg-gray-50 transition-colors duration-150;
            }
            .badge {
                @apply px-2 py-1 rounded-full text-xs font-medium;
            }
            .badge-success {
                @apply bg-success/10 text-success;
            }
            .badge-danger {
                @apply bg-danger/10 text-danger;
            }
            .badge-warning {
                @apply bg-warning/10 text-warning;
            }
            .badge-info {
                @apply bg-primary/10 text-primary;
            }
        }
    </style>
</head>
<body class="bg-gray-50 text-gray-800 min-h-screen flex flex-col">
    <!-- 顶部导航 -->
    <header class="bg-primary text-white shadow-md">
        <div class="container mx-auto px-4 py-3 flex justify-between items-center">
            <div class="flex items-center space-x-2">
                <i class="fa fa-bank text-2xl"></i>
                <h1 class="text-xl font-semibold">银行业务管理系统</h1>
            </div>
            <div class="flex items-center space-x-6">
                <div class="relative">
                    <button class="flex items-center space-x-2 focus:outline-none">
                        <i class="fa fa-bell-o"></i>
                        <span class="absolute -top-1 -right-1 bg-danger text-white text-xs rounded-full h-4 w-4 flex items-center justify-center">3</span>
                    </button>
                </div>
                <div class="flex items-center space-x-2">
                    <img src="https://picsum.photos/id/1005/40/40" alt="用户头像" class="w-8 h-8 rounded-full object-cover">
                    <span>管理员</span>
                </div>
            </div>
        </div>
    </header>

    <!-- 主体内容 -->
    <main class="flex-1 overflow-auto p-6 bg-gray-50">
        <!-- 面包屑导航 -->
        <div class="mb-6 flex items-center text-sm text-gray-500">
            <a href="#" class="hover:text-primary">首页</a>
            <i class="fa fa-angle-right mx-2 text-xs"></i>
            <span class="text-gray-700">交易管理</span>
        </div>

        <!-- 页面标题 -->
        <div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between">
            <div>
                <h2 class="text-2xl font-semibold text-gray-800">交易管理</h2>
                <p class="text-gray-500 mt-1">查看和管理所有交易记录</p>
            </div>
            <div class="mt-4 md:mt-0 flex space-x-3">
                <button id="addTransactionBtn" class="btn-primary flex items-center">
                    <i class="fa fa-plus mr-2"></i>添加交易
                </button>
                <button id="exportCsvBtn" class="btn-warning flex items-center">
                    <i class="fa fa-file-text-o mr-2"></i>导出CSV
                </button>
            </div>
        </div>

        <!-- 搜索和筛选区域 -->
        <div class="bg-white rounded-lg p-6 card-shadow mb-6">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">交易时间</label>
                    <div class="relative">
                        <input type="date" id="transactionDate" class="input-control w-full pl-10">
                        <i class="fa fa-calendar absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
                    </div>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">交易类型</label>
                    <select id="transactionType" class="input-control w-full">
                        <option value="">全部类型</option>
                        <option value="deposit">存款</option>
                        <option value="withdraw">取款</option>
                        <option value="transfer">转账</option>
                        <option value="payment">支付</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">卡号</label>
                    <div class="relative">
                        <input type="text" id="cardNumber" placeholder="输入卡号" class="input-control w-full pl-10">
                        <i class="fa fa-credit-card absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
                    </div>
                </div>
                <div class="flex items-end">
                    <button id="searchBtn" class="btn-primary w-full">
                        <i class="fa fa-search mr-2"></i>搜索
                    </button>
                </div>
            </div>
        </div>

        <!-- 交易记录表格 -->
        <div class="bg-white rounded-lg p-6 card-shadow">
            <div class="flex justify-between items-center mb-6">
                <h3 class="font-semibold">交易记录列表</h3>
                <div class="text-sm text-gray-500" id="recordCount">共 0 条交易记录</div>
            </div>

            <div class="overflow-x-auto">
                <table class="min-w-full">
                    <thead>
                        <tr class="bg-gray-50 text-left">
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">
                                <input type="checkbox" id="selectAll" class="rounded text-primary focus:ring-primary">
                            </th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">交易时间</th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">交易类型</th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">交易金额</th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">卡号</th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider">备注</th>
                            <th class="py-3 px-4 text-xs font-medium text-gray-500 uppercase tracking-wider text-right">操作</th>
                        </tr>
                    </thead>
                    <tbody id="transactionTableBody" class="divide-y divide-gray-200">
                        <!-- 交易记录将通过JavaScript动态生成 -->
                        <tr class="text-center">
                            <td colspan="7" class="px-6 py-12 text-gray-500">
                                <div class="flex flex-col items-center">
                                    <i class="fa fa-search text-4xl mb-4 text-gray-300"></i>
                                    <p>暂无交易记录，请添加或搜索交易</p>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            <div class="mt-6 flex flex-col sm:flex-row items-center justify-between">
                <div class="text-sm text-gray-500 mb-4 sm:mb-0">
                    显示 <span id="startIndex">0</span> 到 <span id="endIndex">0</span> 条，共 <span id="totalRecords">0</span> 条记录
                </div>
                <div class="flex items-center space-x-1">
                    <button id="prevPage" class="px-3 py-1 rounded border border-gray-300 text-gray-500 hover:border-primary hover:text-primary disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                        <i class="fa fa-chevron-left text-xs"></i>
                    </button>
                    <button id="nextPage" class="px-3 py-1 rounded border border-gray-300 text-gray-500 hover:border-primary hover:text-primary disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                        <i class="fa fa-chevron-right text-xs"></i>
                    </button>
                </div>
            </div>
        </div>
    </main>

    <!-- 页脚 -->
    <footer class="bg-white border-t border-gray-200 py-4">
        <div class="container mx-auto px-4 text-center text-gray-500 text-sm">
            <p>咨询电话：123456 | 工作时间：工作日9:00-12:00,14:00-17:00</p>
            <p>© 2025 **银行 版权所有</p>
        </div>
    </footer>

    <!-- 添加交易模态框 -->
    <div id="addTransactionModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg w-full max-w-md p-6 transform transition-all">
            <div class="flex justify-between items-center mb-4">
                <h3 class="font-semibold text-lg">添加交易记录</h3>
                <button id="closeAddModal" class="text-gray-400 hover:text-gray-600">
                    <i class="fa fa-times"></i>
                </button>
            </div>
            <form id="addTransactionForm">
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">交易时间</label>
                        <input type="datetime-local" id="addTransactionTime" class="input-control w-full" required>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">交易类型</label>
                        <select id="addTransactionType" class="input-control w-full" required>
                            <option value="deposit">存款</option>
                            <option value="withdraw">取款</option>
                            <option value="transfer">转账</option>
                            <option value="payment">支付</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">交易金额</label>
                        <div class="relative">
                            <span class="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400">¥</span>
                            <input type="number" id="addAmount" step="0.01" class="input-control w-full pl-10" required>
                        </div>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">卡号</label>
                        <input type="text" id="addCardNumber" placeholder="输入16-19位卡号" class="input-control w-full" required>
                        <div id="cardNumberError" class="error-message hidden text-danger text-xs mt-1">请输入有效的卡号</div>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">备注</label>
                        <textarea id="addRemark" rows="2" class="input-control w-full" placeholder="可选，输入交易备注信息"></textarea>
                    </div>
                </div>
                <div class="mt-6 flex justify-end space-x-3">
                    <button type="button" id="cancelAddTransaction" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">取消</button>
                    <button type="submit" class="btn-primary">保存交易</button>
                </div>
            </form>
        </div>
    </div>

    <!-- 删除确认模态框 -->
    <div id="deleteModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg w-full max-w-md p-6 transform transition-all">
            <div class="text-center mb-4">
                <div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-danger/10 mb-4">
                    <i class="fa fa-exclamation-triangle text-danger text-2xl"></i>
                </div>
                <h3 class="text-lg font-semibold">确认删除</h3>
                <p class="text-gray-500 mt-2">您确定要删除这条交易记录吗？此操作不可撤销。</p>
                <input type="hidden" id="deleteTransactionId">
            </div>
            <div class="flex justify-center space-x-3">
                <button id="cancelDelete" class="px-4 py-2 border border-gray-300 rounded-md hover:bg-gray-50 transition-colors">
                    取消
                </button>
                <button id="confirmDelete" class="btn-danger">
                    确认删除
                </button>
            </div>
        </div>
    </div>

    <!-- 通知组件 -->
    <div id="notification" class="fixed top-4 right-4 z-50 max-w-xs bg-white rounded-lg shadow-lg p-4 transform translate-x-full transition-transform duration-300 flex items-start">
        <div id="notificationIcon" class="w-8 h-8 rounded-full flex items-center justify-center mr-3 bg-primary/10">
            <i class="fa fa-info text-primary"></i>
        </div>
        <div class="flex-1">
            <h4 id="notificationTitle" class="font-medium text-gray-900">通知标题</h4>
            <p id="notificationMessage" class="text-sm text-gray-500 mt-1">通知内容将显示在这里...</p>
        </div>
        <button id="closeNotification" class="text-gray-400 hover:text-gray-600 ml-2">
            <i class="fa fa-times"></i>
        </button>
    </div>

    <script>
        // 交易数据模型
        let transactionData = [
            {
                id: 1,
                time: '2025-06-20T10:30:00',
                type: 'deposit',
                amount: 5000.00,
                cardNumber: '6222021234567890123',
                remark: '工资存款'
            },
            {
                id: 2,
                time: '2025-06-19T15:45:00',
                type: 'withdraw',
                amount: 2000.00,
                cardNumber: '6222021234567890123',
                remark: 'ATM取款'
            },
            {
                id: 3,
                time: '2025-06-18T09:10:00',
                type: 'transfer',
                amount: 3000.00,
                cardNumber: '6222032345678901234',
                remark: '转账给张三'
            },
            {
                id: 4,
                time: '2025-06-17T14:20:00',
                type: 'payment',
                amount: 500.00,
                cardNumber: '6222043456789012345',
                remark: '网上购物支付'
            }
        ];

        // 分页参数
        let currentPage = 1;
        const itemsPerPage = 10;
        let filteredData = [...transactionData];

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化日期为今天
            const today = new Date();
            const dateStr = today.toISOString().split('T')[0];
            document.getElementById('transactionDate').value = dateStr;
            document.getElementById('addTransactionTime').value = today.toISOString().slice(0, 16);

            // 初始化事件监听
            initEventListeners();

            // 加载交易数据
            loadTransactions();
        });

        // 初始化事件监听
        function initEventListeners() {
            // 添加交易按钮
            document.getElementById('addTransactionBtn').addEventListener('click', showAddTransactionModal);
            document.getElementById('closeAddModal').addEventListener('click', hideAddTransactionModal);
            document.getElementById('cancelAddTransaction').addEventListener('click', hideAddTransactionModal);
            document.getElementById('addTransactionForm').addEventListener('submit', saveTransaction);

            // 搜索按钮
            document.getElementById('searchBtn').addEventListener('click', searchTransactions);

            // 导出CSV按钮
            document.getElementById('exportCsvBtn').addEventListener('click', exportToCsv);

            // 删除模态框按钮
            document.getElementById('cancelDelete').addEventListener('click', hideDeleteModal);
            document.getElementById('confirmDelete').addEventListener('click', deleteTransaction);

            // 分页按钮
            document.getElementById('prevPage').addEventListener('click', prevPage);
            document.getElementById('nextPage').addEventListener('click', nextPage);

            // 全选复选框
            document.getElementById('selectAll').addEventListener('click', toggleSelectAll);

            // 通知关闭按钮
            document.getElementById('closeNotification').addEventListener('click', closeNotification);
        }

        // 加载交易数据
        function loadTransactions() {
            const start = (currentPage - 1) * itemsPerPage;
            const end = start + itemsPerPage;
            const currentPageData = filteredData.slice(start, end);

            const tableBody = document.getElementById('transactionTableBody');
            let html = '';

            if (currentPageData.length === 0 && filteredData.length > 0) {
                html = `
                    <tr class="text-center">
                        <td colspan="7" class="px-6 py-12 text-gray-500">
                            <div class="flex flex-col items-center">
                                <i class="fa fa-search text-4xl mb-4 text-gray-300"></i>
                                <p>没有找到符合条件的交易记录</p>
                            </div>
                        </td>
                    </tr>
                `;
            } else if (currentPageData.length === 0 && filteredData.length === 0) {
                html = `
                    <tr class="text-center">
                        <td colspan="7" class="px-6 py-12 text-gray-500">
                            <div class="flex flex-col items-center">
                                <i class="fa fa-search text-4xl mb-4 text-gray-300"></i>
                                <p>暂无交易记录，请添加或搜索交易</p>
                            </div>
                        </td>
                    </tr>
                `;
            } else {
                currentPageData.forEach(transaction => {
                    html += `
                        <tr class="table-row-hover">
                            <td class="py-3 px-4">
                                <input type="checkbox" class="transaction-checkbox" data-id="${transaction.id}">
                            </td>
                            <td class="py-3 px-4">
                                <div class="text-sm text-gray-900">${formatDateTime(transaction.time)}</div>
                            </td>
                            <td class="py-3 px-4">
                                <div class="text-sm ${getTypeClass(transaction.type)}">${getTypeName(transaction.type)}</div>
                            </td>
                            <td class="py-3 px-4">
                                <div class="text-sm font-medium ${transaction.amount >= 0 ? 'text-success' : 'text-danger'}">${transaction.amount >= 0 ? '+' : ''}¥${transaction.amount.toFixed(2)}</div>
                            </td>
                            <td class="py-3 px-4">
                                <div class="text-sm text-gray-900">${maskCardNumber(transaction.cardNumber)}</div>
                            </td>
                            <td class="py-3 px-4">
                                <div class="text-sm text-gray-700">${transaction.remark || '无'}</div>
                            </td>
                            <td class="py-3 px-4 text-right text-sm font-medium">
                                <button onclick="showDeleteModal(${transaction.id})" class="text-danger hover:text-danger/80">
                                    <i class="fa fa-trash"></i>
                                </button>
                            </td>
                        </tr>
                    `;
                });
            }

            tableBody.innerHTML = html;
            updatePagination();
            updateRecordCount();
        }

        // 更新分页信息
        function updatePagination() {
            const totalPages = Math.ceil(filteredData.length / itemsPerPage);
            const start = (currentPage - 1) * itemsPerPage + 1;
            const end = Math.min(currentPage * itemsPerPage, filteredData.length);

            document.getElementById('startIndex').textContent = filteredData.length > 0 ? start : 0;
            document.getElementById('endIndex').textContent = end;
            document.getElementById('totalRecords').textContent = filteredData.length;
            document.getElementById('recordCount').textContent = `共 ${filteredData.length} 条交易记录`;

            // 更新分页按钮状态
            document.getElementById('prevPage').disabled = currentPage === 1;
            document.getElementById('nextPage').disabled = currentPage >= totalPages;
        }

        // 更新记录计数
        function updateRecordCount() {
            document.getElementById('recordCount').textContent = `共 ${filteredData.length} 条交易记录`;
        }

        // 上一页
        function prevPage() {
            if (currentPage > 1) {
                currentPage--;
                loadTransactions();
            }
        }

        // 下一页
        function nextPage() {
            const totalPages = Math.ceil(filteredData.length / itemsPerPage);
            if (currentPage < totalPages) {
                currentPage++;
                loadTransactions();
            }
        }

        // 显示添加交易模态框
        function showAddTransactionModal() {
            document.getElementById('addTransactionModal').classList.remove('hidden');
            document.getElementById('addTransactionModal').querySelector('div').classList.add('scale-100');
            document.getElementById('addTransactionModal').querySelector('div').classList.remove('scale-95');
            document.getElementById('addCardNumberError').classList.add('hidden');
        }

        // 隐藏添加交易模态框
        function hideAddTransactionModal() {
            document.getElementById('addTransactionModal').querySelector('div').classList.add('scale-95');
            document.getElementById('addTransactionModal').querySelector('div').classList.remove('scale-100');
            setTimeout(() => {
                document.getElementById('addTransactionModal').classList.add('hidden');
            }, 200);
        }

        // 保存交易记录
        function saveTransaction(e) {
            e.preventDefault();

            const time = document.getElementById('addTransactionTime').value;
            const type = document.getElementById('addTransactionType').value;
            const amount = parseFloat(document.getElementById('addAmount').value);
            const cardNumber = document.getElementById('addCardNumber').value;
            const remark = document.getElementById('addRemark').value;

            // 验证表单
            if (!time) {
                showNotification('错误', '请选择交易时间', 'error');
                return;
            }

            if (!type) {
                showNotification('错误', '请选择交易类型', 'error');
                return;
            }

            if (isNaN(amount) || amount <= 0) {
                showNotification('错误', '请输入有效的交易金额', 'error');
                return;
            }

            if (!validateCardNumber(cardNumber)) {
                document.getElementById('cardNumberError').classList.remove('hidden');
                return;
            }

            // 创建新交易记录
            const newTransaction = {
                id: transactionData.length > 0 ? Math.max(...transactionData.map(t => t.id)) + 1 : 1,
                time: time,
                type: type,
                amount: amount,
                cardNumber: cardNumber,
                remark: remark
            };

            // 添加到数据数组
            transactionData.unshift(newTransaction);
            filteredData = [...transactionData];
            currentPage = 1;

            // 刷新表格
            loadTransactions();

            // 隐藏模态框
            hideAddTransactionModal();

            // 显示成功通知
            showNotification('成功', '交易记录添加成功', 'success');
        }

        // 验证卡号
        function validateCardNumber(cardNumber) {
            return /^\d{16,19}$/.test(cardNumber);
        }

        // 显示删除模态框
        function showDeleteModal(transactionId) {
            document.getElementById('deleteTransactionId').value = transactionId;
            document.getElementById('deleteModal').classList.remove('hidden');
            document.getElementById('deleteModal').querySelector('div').classList.add('scale-100');
            document.getElementById('deleteModal').querySelector('div').classList.remove('scale-95');
        }

        // 隐藏删除模态框
        function hideDeleteModal() {
            document.getElementById('deleteModal').querySelector('div').classList.add('scale-95');
            document.getElementById('deleteModal').querySelector('div').classList.remove('scale-100');
            setTimeout(() => {
                document.getElementById('deleteModal').classList.add('hidden');
            }, 200);
        }

        // 删除交易记录
        function deleteTransaction() {
            const transactionId = parseInt(document.getElementById('deleteTransactionId').value);
            transactionData = transactionData.filter(t => t.id !== transactionId);
            filteredData = [...transactionData];
            currentPage = 1;

            // 刷新表格
            loadTransactions();

            // 隐藏模态框
            hideDeleteModal();

            // 显示成功通知
            showNotification('成功', '交易记录删除成功', 'success');
        }

        // 搜索交易记录
        function searchTransactions() {
            const date = document.getElementById('transactionDate').value;
            const type = document.getElementById('transactionType').value;
            const cardNumber = document.getElementById('cardNumber').value;

            // 过滤数据
            filteredData = transactionData.filter(transaction => {
                const matchDate = !date || transaction.time.startsWith(date);
                const matchType = !type || transaction.type === type;
                const matchCardNumber = !cardNumber || transaction.cardNumber.includes(cardNumber);

                return matchDate && matchType && matchCardNumber;
            });

            currentPage = 1;
            loadTransactions();
        }

        // 导出为CSV
        function exportToCsv() {
            if (filteredData.length === 0) {
                showNotification('提示', '没有可导出的交易记录', 'warning');
                return;
            }

            // 构建CSV内容
            let csvContent = "交易时间,交易类型,交易金额,卡号,备注\n";
            filteredData.forEach(transaction => {
                csvContent += `"${formatDateTime(transaction.time)}","${getTypeName(transaction.type)}","${transaction.amount.toFixed(2)}","${transaction.cardNumber}","${transaction.remark || ''}"\n`;
            });

            // 创建CSV文件
            const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
            const url = URL.createObjectURL(blob);
            const link = document.createElement("a");
            link.setAttribute("href", url);
            link.setAttribute("download", `交易记录_${new Date().toISOString().slice(0, 10)}.csv`);
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);

            // 显示成功通知
            showNotification('成功', '交易记录导出成功', 'success');
        }

        // 全选/取消全选
        function toggleSelectAll() {
            const selectAll = document.getElementById('selectAll');
            const checkboxes = document.querySelectorAll('.transaction-checkbox');

            checkboxes.forEach(checkbox => {
                checkbox.checked = selectAll.checked;
            });
        }

        // 格式化日期时间
        function formatDateTime(dateTime) {
            const date = new Date(dateTime);
            return date.toLocaleString('zh-CN', {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit'
            });
        }

        // 获取交易类型名称
        function getTypeName(type) {
            const types = {
                'deposit': '存款',
                'withdraw': '取款',
                'transfer': '转账',
                'payment': '支付'
            };
            return types[type] || type;
        }

        // 获取交易类型对应的CSS类
        function getTypeClass(type) {
            const classes = {
                'deposit': 'text-success',
                'withdraw': 'text-danger',
                'transfer': 'text-primary',
                'payment': 'text-warning'
            };
            return classes[type] || 'text-gray-700';
        }

        // 卡号脱敏
        function maskCardNumber(cardNumber) {
            if (!cardNumber) return '';
            const prefix = cardNumber.substring(0, 4);
            const suffix = cardNumber.substring(cardNumber.length - 4);
            return `${prefix} **** **** ${suffix}`;
        }

        // 显示通知
        function showNotification(title, message, type = 'info') {
            const notification = document.getElementById('notification');
            const notificationTitle = document.getElementById('notificationTitle');
            const notificationMessage = document.getElementById('notificationMessage');
            const notificationIcon = document.getElementById('notificationIcon');

            // 设置通知内容
            notificationTitle.textContent = title;
            notificationMessage.textContent = message;

            // 设置通知类型样式
            notificationIcon.className = 'w-8 h-8 rounded-full flex items-center justify-center mr-3';
            let iconClass = 'fa fa-info';
            let bgClass = 'bg-primary/10';

            if (type === 'success') {
                iconClass = 'fa fa-check';
                bgClass = 'bg-success/10';
            } else if (type === 'warning') {
                iconClass = 'fa fa-exclamation';
                bgClass = 'bg-warning/10';
            } else if (type === 'error') {
                iconClass = 'fa fa-times';
                bgClass = 'bg-danger/10';
            }

            notificationIcon.className = `${bgClass} w-8 h-8 rounded-full flex items-center justify-center mr-3`;
            notificationIcon.innerHTML = `<i class="fa ${iconClass} text-${type === 'error' ? 'danger' : type === 'warning' ? 'warning' : type === 'success' ? 'success' : 'primary'}"></i>`;

            // 显示通知
            notification.classList.remove('translate-x-full');

            // 3秒后自动关闭
            setTimeout(closeNotification, 3000);
        }

        // 关闭通知
        function closeNotification() {
            const notification = document.getElementById('notification');
            notification.classList.add('translate-x-full');
        }
    </script>
</body>
</html>